package com.zhao.modleclass.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhao.modleclass.Helper.BitmapCircleTransformation;
import com.zhao.modleclass.Helper.RecyclerViewAdapterHelper;
import com.zhao.modleclass.R;
import com.zhao.modleclass.activity.SC_TeacherWebView;
import com.zhao.modleclass.bean.SearchClassItemBean;
import com.zhao.modleclass.utils.Constant;

import java.util.List;

/**
 * Created by 张昭 on 2016/12/10.
 */

public class SC_MoDenTeacherAdapter extends RecyclerViewAdapterHelper {
     private Context mContext;
    private List<SearchClassItemBean.DataBean> mList;
    private RecyclerView recyclerView;
    public SC_MoDenTeacherAdapter(Context context, List list,RecyclerView recyclerView) {
        super(context, list);
        this.mContext=context;
        this.mList=list;
        this.recyclerView=recyclerView;
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view=mInflater.inflate(R.layout.item_mdls_searchclass,parent,false);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //找到点击的每一个item的ID
                int position=recyclerView.getChildLayoutPosition(v);
                //找到点击的每一个item的网址
                String url= Constant.Item_URL+mList.get(position).getTechId();
                String titleName=mList.get(position).getTechNickName();
                Bundle bundle=new Bundle();
                bundle.putString("url",url);
                bundle.putString("name",titleName);
                //intent跳转
                Intent intent = new Intent(mContext, SC_TeacherWebView.class);
                intent.putExtra("url", bundle);
                intent.putExtra("name",bundle);
                //启动跳转
                mContext.startActivity(intent);
            }
        });

        return new MyHolder(view);
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
            if (holder instanceof MyHolder){
                Glide.with(mContext).
                        load(mList.get(position).getTechHeadUrl()).
                        transform(new BitmapCircleTransformation(mContext)).
                        into(((MyHolder) holder).imageView_1);
                Glide.with(mContext).
                        load(mList.get(position).getTechIconUrl()).
                        transform(new BitmapCircleTransformation(mContext)).
                        into(((MyHolder) holder).imageView_2);
                ((MyHolder) holder).textView_1.setText(mList.get(position).getTechNickName());
                ((MyHolder) holder).textView_2.setText(mList.get(position).getTechJobName());
                ((MyHolder) holder).textView_3.setText(mList.get(position).getCourseTotal()+"");
                ((MyHolder) holder).textView_4.setText(mList.get(position).getFollowTotal()+"");
                ((MyHolder) holder).textView_5.setText(mList.get(position).getTechDesc());

            }
    }
    class MyHolder extends RecyclerView.ViewHolder {
        private ImageView imageView_1,imageView_2;
        private TextView textView_1,textView_2,textView_3,textView_4,textView_5;
        public MyHolder(View itemView) {
            super(itemView);
            imageView_1= (ImageView) itemView.findViewById(R.id.imageView_item_mdls_searchclass_icon);
            imageView_2= (ImageView) itemView.findViewById(R.id.imageView_item_mdls_searchclass_tag);
            textView_1= (TextView) itemView.findViewById(R.id.textView_item_mdls_searchclass_title);
            textView_2= (TextView) itemView.findViewById(R.id.textView_item_mdls_searchclass_biaoti);
            textView_3= (TextView) itemView.findViewById(R.id.textView_item_mdls_searchclass_dianshi);
            textView_4= (TextView) itemView.findViewById(R.id.textView_item_mdls_searchclass_renshu);
            textView_5= (TextView) itemView.findViewById(R.id.textView_item_mdls_searchclass_p);
        }
    }
}
